﻿using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using Texfina.Core.Common;  
using Texfina.Core.Web;
using Texfina.Common.Mg;
using Texfina.Core.Data;  
using Texfina.Entity.Mg;
using MGBOQry = Texfina.BOQry.Mg;

namespace MG
{
   public partial class wfTablaGenBnd : SearchPage 
   {
        public const int _GRDLIST_STANULADO = 5;

      protected void Page_Load(object sender, EventArgs e)
      {
                       
         this.LoadInitialSettings();
         if(this.IsPostBack){
            this.LoadInPostBack();
            return;
         } 

         this.LoadData();
         SearchData();

      }

      public override void LoadInitialSettings()
      {
         Label lbl = (Label) this.Master.FindControl("lblTitle");
         lbl.Text = "Tabla General";
         this.Page.Form.DefaultButton = bttSearch.UniqueID;
      }

      public override void SearchData()
      {
         ETablaGen ObjE = new ETablaGen();
    
          
         //objE.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
         if (this.txtidTabla.Text == "")
            ObjE.IdTabla = null;
         else
            ObjE.IdTabla = this.txtidTabla .Text;

         if (this.txtdsTabla.Text == "")
            ObjE.DsTabla = null;
         else
            ObjE.DsTabla = this.txtdsTabla.Text;

         IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(MGBOQry.TablaGen));
         DataTable dt = objBO.GetByCriteria(ObjE);

         this.GridSetDataBinding(grdList, dt);

      }

      protected void mnuToolbar_MenuItemClick(Object sender, MenuEventArgs e)
      {
          String strQS= "";

         switch(e.Item.Value){
            case ConstMenuToolbarValue.BUTTON_NEW:
               strQS = "wfTablaGenMnt.aspx?formEA=" + Convert.ToInt32(FormEditAction.AddNew).ToString() + "&idTabla=";
                 break;
         }
         Response.Redirect(strQS);
      }

      protected void grdList_RowCommand(Object sender, GridViewCommandEventArgs e)
      {
          DataRow dr = this.GridGetRowFromDataKey(grdList, Convert.ToInt32(e.CommandArgument));
          FormEditAction formEA = FormEditAction.AddNew;

          switch (e.CommandName)
          {
              case ConstGridRowCommand.GRIDEDIT:
                  formEA = FormEditAction.Edit;
                  break;
              case ConstGridRowCommand.GRIDDELETE:
                  formEA = FormEditAction.Delete;
                  break;
              case ConstGridRowCommand.GRIDPREVIEW:
                  //this.PrintReport(Convert.ToInt32(e.CommandArgument));
                  return;
          }
          String strQS = "wfTablaGenMnt.aspx?formEA=" + Convert.ToInt32(formEA).ToString() + "&idTabla=" + dr["idTabla"].ToString();
         Response.Redirect(strQS);
      
      }

      protected void bttOk_Click(object sender, EventArgs e)
      {
          this.SearchData();
      }
   }
}